package com.xuanxing123.model;

import com.xuanxing123.model.BaseObject;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="industry",catalog="xuanxing")
@Searchable
@XmlRootElement
public class Industry extends BaseObject implements Serializable {
    private Long id;
    private String comments;
    private String name;
    private Integer position;
    private Set<IndustrySegment> industrySegments = new HashSet<IndustrySegment>(0);

    @Id @GeneratedValue(strategy=IDENTITY)
    @SearchableId
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="comments", length=254)
    @SearchableProperty
    public String getComments() {
        return this.comments;
    }
    
    public void setComments(String comments) {
        this.comments = comments;
    }
    
    @Column(name="name", nullable=false, length=100)
    @SearchableProperty
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="position", nullable=false)
    @SearchableProperty
    public Integer getPosition() {
        return this.position;
    }
    
    public void setPosition(Integer position) {
        this.position = position;
    }
@OneToMany(fetch=FetchType.LAZY, mappedBy="industry")
    public Set<IndustrySegment> getIndustrySegments() {
        return this.industrySegments;
    }
    
    public void setIndustrySegments(Set<IndustrySegment> industrySegments) {
        this.industrySegments = industrySegments;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Industry pojo = (Industry) o;

        if (comments != null ? !comments.equals(pojo.comments) : pojo.comments != null) return false;
        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
        if (position != null ? !position.equals(pojo.position) : pojo.position != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (comments != null ? comments.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (position != null ? position.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("comments").append("='").append(getComments()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("position").append("='").append(getPosition()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }

}
